
using System;
using SpecMaker.Core.Interfaces;

namespace SpecMaker.Core
{
    public class ConsoleReportFactory : IReportFactory
    {
        private readonly IConsoleWrapper _wrapper;

        public ConsoleReportFactory(IConsoleWrapper wrapper)
        {
            _wrapper = wrapper;
        }

        public void FromSpecContainers(SpecResult[] specs)
        {
             
            foreach (var spec in specs)
            {
               
                _wrapper.WriteLine(spec.SpecObject);
                _wrapper.WriteLine("\t"+spec.Context);
                foreach (var item in spec.Results)
                {
                    var currentcolor = _wrapper.ForegroundColor;
                     _wrapper.Write("\t - It Should " + item.Description + " - " );
                    DisplayItem(item.Status, currentcolor);
                    if(!string.IsNullOrEmpty(item.ErrorMessage))
                    {


                        _wrapper.WriteLine("\t Stack Trace:");
                        _wrapper.WriteLine("\t --------------------------------------");
                       
                        _wrapper.WriteLine("\t" + item.ErrorMessage);
                        _wrapper.WriteLine("\t -------------------------------------");
                        _wrapper.WriteLine("\n");
                    }

                   
                }
                
            }
            
            
        }
        private void DisplayItem(RuleStatus status, ConsoleColor original)
        {
            
            if (status == RuleStatus.Error)
                _wrapper.ForegroundColor = ConsoleColor.Red;
            _wrapper.WriteLine(status.DisplayName);
            _wrapper.ForegroundColor = original;
        }
    }
}